1. Field of the Invention
This invention generally relates to a data processing system and, more particularly, to a method and system in an object-oriented data processing system for generating proxy classes at runtime that implement a list of interfaces specified at runtime.
2. Related Art
Many computing systems use object-oriented programming to better accommodate the increasing complexity and cost of large computer programs. Object-orient programming languages have grown to be widely used due to their programming power and efficiency. In an object-oriented computing system, source code written in an object-oriented programming language, such as the Java™ programming language, typically contains a number of “classes,” such as Java classes. A class is a template for creating objects that are “instances” of the class and are created from the template. A class contains both data members that store data and function members (or “methods”) that act upon the data. Consequently, the class of an object defines its data and behavior, and the methods (function members) are typically used to both get and set the values for the data members in the class.
Additionally, object-oriented programming languages such as the Java programming language utilize “interfaces,” which are simply lists of methods. An interface is similar to a class but typically only has declarations of its methods and typically does not provide implementation of those methods. An interface specifies methods supported by classes that implement the interface and declares what those methods should do. Classes, instances, interfaces and other aspects of object-oriented programming languages are discussed in detail in “The Java Programming Language”, 2nd Ed., Ken Arnold, James Gosling, Addison-Wesley, 1998, which is incorporated herein by reference. For further description of the Java language, refer to “The Java Language Specification,” James Gosling, Bill Joy, Guy Steele, Addison-Wesley, 1996, which is also incorporated herein by reference.
When the source code for classes, interfaces and other aspects of an object-oriented programming language are created, they are usually written by a user and then compiled by a compiler on a computer so that the computer may run the source code. The source code is written and then compiled at a stage referred to as “compile-time.” After the source code has been built and compiled, a computer system may then execute the source code at “runtime.”
Since a class typically has to be built offline and then compiled, the interfaces implemented by that class must typically be known while the class is being built before runtime. Conventionally, to implement an interface by a class, the methods of the interface are determined during source code development before compile-time. For example, section 4.5 of Arnold and Gosling's “The Java Programming Language” describes an approach called “forwarding” to make a class use a second class for the implementation of one of its interfaces. This approach is simply to define every single method of the interface in the first class to delegate to the corresponding method in the second class. However, section 4.7 characterizes this approach as “tedious to implement and error-prone,” which is further demonstrated by the fact that compile-time tools have been developed to automate the process of generating these forwarding methods.
Sometimes the interfaces that a user would like to implement may not be known or may be changing during the runtime of the program. As a result, it would be desirable to have a method and system that avoids the need to generate before runtime a class that implements a list of interfaces and avoids the need to write and compile code for each method of an interface being implemented.
Conventionally, to implement a single functionality on multiple interfaces of varying types, code needs to be created for each interface to carry out the functionality. It would also be desirable to not require the writing of specialized code for each one of multiple types of interfaces to facilitate a single functionality.